package com.dayuanit.dy17.mix.thread;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

public class TestThreadPool {

    private static final Queue<String> queue = new ArrayBlockingQueue(100);

    public static void main(String[] args) {
        //处理邮件的发送

        new Thread(new Runnable() {
            @Override
            public void run() {
                int num = 1000;
                while(true) {
                    queue.add((num ++) + "@qq.com");
                    try {
                        Thread.sleep(1*1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"生产者").start();

        //消费者
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {

                    String email = queue.poll();
                    System.out.println("发送邮件" + email);

                    try {
                        Thread.sleep(1 * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t1").start();


        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {

                    String email = queue.poll();
                    System.out.println("发送邮件" + email);

                    try {
                        Thread.sleep(1 * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t2").start();

//        queue.addLast("a");
//        queue.addLast("b");
//        queue.addLast("c");
//        System.out.println(queue.pollFirst());
//        System.out.println(queue.pollFirst());
//        System.out.println(queue.pollFirst());

    }
}
